<?php

function ambil_bulan($bln) {
	switch($bln) {
	case 1 : $nama_bulan = "Januari" ; break;
	case 2 : $nama_bulan = "Februari" ; break;
	case 3 : $nama_bulan = "Maret" ; break;
	case 4 : $nama_bulan = "April" ; break;
	case 5 : $nama_bulan = "Mei" ; break;
	case 6 : $nama_bulan = "Juni" ; break;
	case 7 : $nama_bulan = "Juli" ; break;
	case 8 : $nama_bulan = "Agustus" ; break;
	case 9 : $nama_bulan = "September" ; break;
	case 10 : $nama_bulan = "Oktober" ; break;
	case 11 : $nama_bulan = "November" ; break;
	case 12 : $nama_bulan = "Desember" ; break;
	default:$nama_bulan="";
	}
	return $nama_bulan ;
}

function bulan_pendek($bln){
	switch($bln) {
	case 1 : $nama_bulan = "Jan" ; break;
	case 2 : $nama_bulan = "Feb" ; break;
	case 3 : $nama_bulan = "Mar" ; break;
	case 4 : $nama_bulan = "Apr" ; break;
	case 5 : $nama_bulan = "Mei" ; break;
	case 6 : $nama_bulan = "Jun" ; break;
	case 7 : $nama_bulan = "Jul" ; break;
	case 8 : $nama_bulan = "Agus" ; break;
	case 9 : $nama_bulan = "Sep" ; break;
	case 10 : $nama_bulan = "Okt" ; break;
	case 11 : $nama_bulan = "Nov" ; break;
	case 12 : $nama_bulan = "Des" ; break;
	default:$nama_bulan="";
	}
	return $nama_bulan ;
}

function hitung_denda($arr_nominal){
	$total=0;
	$persen=0.05;
	$banyak=count($arr_nominal);
	for($i=0;$i<$banyak;$i++){
		$nominal=$arr_nominal[$i];
		if($i>2){
			//echo ' loop '.$i.' ke '.$total.' tot ';
			$denda=$persen*$total;
			//echo $denda.' harus ';
			$harus=$denda+$nominal;
			//$tot_harus+=$harus;
			//echo number_format($harus,0,",",".");
			
		}else{
			$harus=$nominal;
		}
		$total+=$harus;
		
	}
	//$bayar_normal=$nominal*$banyak;
	$bayar_normal=array_sum($arr_nominal);
	if($banyak>3){
		$nom_denda=$total-$bayar_normal;
		$data_arr=array('total_bayar'=>$total,'denda'=>$nom_denda,'bayar_normal'=>$bayar_normal);
	}else{
		$data_arr=array('total_bayar'=>$bayar_normal,'denda'=>0,'bayar_normal'=>$bayar_normal);
	}
	return $data_arr;
}

function tgl_indonesia($tgl) {
	$tanggal=substr($tgl,8,2);
	$bulan=ambil_bulan(substr($tgl,5,2));
	$tahun=substr($tgl,0,4);
	return $tanggal." ".$bulan." ".$tahun ;
}

function konvert_periode($str){
	$pecah=explode("-",$str);
	switch($pecah[1]) {
	case 1 : $nama_bulan = "Januari" ; break;
	case 2 : $nama_bulan = "Februari" ; break;
	case 3 : $nama_bulan = "Maret" ; break;
	case 4 : $nama_bulan = "April" ; break;
	case 5 : $nama_bulan = "Mei" ; break;
	case 6 : $nama_bulan = "Juni" ; break;
	case 7 : $nama_bulan = "Juli" ; break;
	case 8 : $nama_bulan = "Agustus" ; break;
	case 9 : $nama_bulan = "September" ; break;
	case 10 : $nama_bulan = "Oktober" ; break;
	case 11 : $nama_bulan = "November" ; break;
	case 12 : $nama_bulan = "Desember" ; break;
	}
	return $nama_bulan." ".$pecah[0];
}

function konvert_periode_pendek($str){
	$pecah=explode("-",$str);
	switch($pecah[1]) {
	case 1 : $nama_bulan = "Jan" ; break;
	case 2 : $nama_bulan = "Feb" ; break;
	case 3 : $nama_bulan = "Mar" ; break;
	case 4 : $nama_bulan = "Apr" ; break;
	case 5 : $nama_bulan = "Mei" ; break;
	case 6 : $nama_bulan = "Jun" ; break;
	case 7 : $nama_bulan = "Jul" ; break;
	case 8 : $nama_bulan = "Agus" ; break;
	case 9 : $nama_bulan = "Sep" ; break;
	case 10 : $nama_bulan = "Okt" ; break;
	case 11 : $nama_bulan = "Nov" ; break;
	case 12 : $nama_bulan = "Des" ; break;
	}
	return $nama_bulan." ".$pecah[0];
}

function get_tapel_aktif(){
	$_this = & get_Instance();
	$_this->load->model("master/master_tapel"); 
	$tapel_aktif=$_this->master_tapel->get_tapel_aktif();
	return $tapel_aktif['th_ajaran'];
}
?>